//
//  BaseViewController.m
//  BuyVegetable
//
//  Created by yushanchang on 16/10/12.
//  Copyright © 2016年 com.yinding. All rights reserved.
//  所有子类的根类

#import "BaseViewController.h"

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
     [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (BVUser *)user {
    if (!_user) {
        _user = [BVUser sharedUser];
    }
    return _user;
}


#pragma mark -
#pragma mark - MBProgressHUD提示相关
/**
 *  弹框提示
 */
- (void)showMessage:(NSString *)text {
    if (self.navigationController != nil) {
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
        hud.mode = MBProgressHUDModeText;
        if (text == nil || [text isEqualToString:@""]) {
            hud.labelText = @"网络异常";
        } else {
            hud.labelText = text;
        }
        hud.margin = 10.f;
        hud.animationType = MBProgressHUDAnimationFade;
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1.5f];
    }
}

/**
 *  显示错误信息
 */
- (void)showError:(NSString *)test {
    [MBProgressHUD showError:test toView:self.navigationController.view];
}
/**
 *  显示成功信息
 */
- (void)showSuccess:(NSString *)text {
    [MBProgressHUD showSuccess:text toView:self.navigationController.view];
}
/**
 *  显示警告信息
 */
- (void)showWarning:(NSString *)text {
    [MBProgressHUD showWarning:text toView:self.navigationController.view];
}

- (MBProgressHUD *)hud {
    if (!_hud) {
        if (self.navigationController != nil) {
            _hud = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
            [self.navigationController.view addSubview:_hud];
            _hud.dimBackground = NO;
            _hud.labelText = NSLocalizedString(@"正在加载", nil);
        } else {
            _hud = [[MBProgressHUD alloc] initWithView:self.view];
            [self.view addSubview:_hud];
            _hud.dimBackground = NO;
            _hud.labelText = NSLocalizedString(@"正在加载", nil);
        }
    }
    return _hud;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
